//区间修改 + 区间查询
//建议除了"区间统一加数和区间求和"这道模版题之外, 其他的 区间修改+区间查询 问题, 首先用线段树解决 
#include <iostream>
using namespace std;
#define lowbit(x) (x & -x)
const int N = 1e6 + 10;
typedef long long ll;
int n, q;
ll d[N];

struct BIT
{
    ll s[N]; 
    
    void modify(int x, ll k)
    {
        for(int i = x; i <= n; i += lowbit(i)) s[i] += k;
    }

    ll query(int x)
    {
        ll sum = 0;
        for(int i = x; i; i -= lowbit(i)) sum += s[i];
        return sum;
    }
}A, B;


int main()
{
    cin >> n >> q;
    for(int i = 1; i <= n; i++)
    {
        ll x; cin >> x;
        d[i] += x, d[i + 1] -= x;
    }

    for(int i = 1; i <= n; i++)
    {
        A.modify(i, d[i]);
        B.modify(i, d[i] * (i - 1));
    }

    while(q--)
    {
        int op, x, y; ll k; 
        cin >> op >> x >> y;
        if(op == 1)
        {
            cin >> k; //区间修改
            A.modify(x, k); A.modify(y + 1, -k);
            B.modify(x, k * (x - 1)); B.modify(y + 1, -k * y);    
        }
        else
        {
            //[1, y], [1, x - 1]
            ll X = A.query(x - 1) * (x - 1) - B.query(x - 1); 
            ll Y = A.query(y) * y - B.query(y); 
            cout << Y - X << endl;
        }
    }
    return 0;
}